package cn.itbeien;

import cn.itbeien.core.util.HttpClient;
import cn.itbeien.core.util.RSAUtils;
import cn.itbeien.request.CommonReqVO;
import cn.itbeien.request.ScanPayReq;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import static cn.itbeien.core.util.RSAUtils.getReqSortStr;

/**
 * @author beien
 * @date $DATE $TIME
 * Copyright© $YEAR beien
 */
public class Main {
    public static void main(String[] args) {
        CommonReqVO commonReqVO = new CommonReqVO();
        commonReqVO.setOrgId("ORG000000004785");//机构编号
        commonReqVO.setOrgMercode("531000013010845");//商户编号
        commonReqVO.setOrgTermno("32812114");//终端编号
        commonReqVO.setOrgTrace("ORG0478520240311170338888230");//聚合支付系统的订单编号
        commonReqVO.setSignType("RSA2");
        ScanPayReq scanPay = new ScanPayReq();
        scanPay.setOrgBackUrl("");//用户支付成功后支付通知后台地址
        scanPay.setOrgFrontUrl("");//前端通知地址
        scanPay.setPayerId("");//用户标识 openid
        scanPay.setTradeCode("WTJS1");//公众号/js支付
        scanPay.setTradeAmt(1l);//支付1分钱
        scanPay.setOrderInfo("测试");//订单标识

        JSONObject jsonObject  = JSON.parseObject(JSON.toJSONString(scanPay));
        //字段排序
        String jsonStr = getReqSortStr(jsonObject);

        //RSA加密生成sign(签名)
        //待加密的字符，私钥
        String privateKey = "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAOSxfpYzsR5pKg0lpDb8rwhmJuaN06l+o9wf5FvKFoGCGt0yMmv/OUqsiFzuatZ7VV2hx/WavOVVubMr6YXD8/GINStC/6Hj7ih30XDjQLM1TRmBfhux+FO3LEYUULKbp/LZz+tXDU6QN6Hvw3CGNRhwdAV5Sq1d0REg7tbPuCZpAgMBAAECgYBigmpqvN2AogAxJZO08+dZkNcU3ObdzeU7fqlZOJW1N5vmyCacCpZdKjCbB0ASH5JIANYnX34as3CIU1QGAMBk63Rm7LYF7mPu3r+qYUhwt60FTynxktkKgvtr2slDNc+oF4noAKvzd3W752RWn/lp9rGvhkk8gljaBVa0A+4A+QJBAP6R2b7dDdmICLJFJV8EdKJjThndSQymS4MLT2p3ZdT2ULhMtLjbOy0FeQaBFEkF6cy8TquIvO76qwlNCPlO5qcCQQDl+mz7s7Pd6SaMcuAMPDnuCNqVZNspseP3WmnB3q/Bt3Ad+dTtoopVYgvrIAb+VxVkZ804k3c192wl9BilVTxvAkEA4I4jdztjRim7EhXwezpg8AWNFT+femsOXRATA6VCzHJijdAL8qxgLLyRH22pSSjQLetFsgYyMtQnH1M2wUQaLQJBAKNDNa02NKF8C+a3AoENHF70oCBgegnOhLSr1dpQuVr/W7OcEWIl+qiEs0tW8EANGF2wJwtb/Mwt+vOypvBwYzcCQQCff7Cv+JHXx+voggV+lJqkBpFGjIV2axQ97n4JrBxwok7y42KEhMrKqVRAzXp7iGSxXfq7AkL0JSU7gSz+dg/3";
        //加过签名的string
        String sign = RSAUtils.sign(jsonStr,privateKey);
        commonReqVO.setSign(sign);//签名
        commonReqVO.setData(scanPay);
        //发起http请求调用
        String url ="https://t-wapi.bhecard.com:8443/standard/jsapi";//js支付
        String requestBody = JSON.toJSONString(commonReqVO);
        String encoding ="UTF-8";
        int timeOut = 10;
        try {
            String message = HttpClient.send(url,requestBody,encoding,encoding,timeOut);
            //message 服务端返回的数据
            System.out.println("message:"+message);
        }catch (Exception e){
            e.printStackTrace();
        }



    }
}